package com.aps.server.parse.controller;

import com.aps.common.boot.CoreApplicationContext;
import com.aps.common.entity.Result;
import com.aps.server.parse.ann.ExcelParser;
import com.aps.server.parse.model.ExcelImportResult;
import com.aps.server.parse.utils.ExcelParserUtil;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Author nbZhuozh
 * 通用导入 导出
 * @Date 2025-08-29  14:42
 **/
public interface GenericParseController {

    public Logger log = LoggerFactory.getLogger(GenericParseController.class);

    /**
     * 导入
     * @param file
     * @return
     */
//    Result<Map<String,Object>> importFile(ExcelRequest file);
    Result<ExcelImportResult> importFile(MultipartFile file, String targetModelName);
    /**
     * 下载模板
     */
    ResponseEntity<byte[]> exportTemplate(ExcelRequest request);

    /**
     * NOTES 获取 对应接受的映射实体
     * @param targetClassName
     * @return
     */
    default Class<?> validateClazz(String targetClassName){
        //获取实体信息
        Class<?> targetClazz ;
        try {
            targetClazz = CoreApplicationContext.getApplicationContext().getBean(targetClassName).getClass();
        } catch (BeansException e){
            log.error("[no such bean] -> {}" ,targetClassName);
            e.printStackTrace();
            return null;
        }
        ExcelParser[] annotationsByType = targetClazz.getAnnotationsByType(ExcelParser.class);
        if(annotationsByType.length == 0){
            log.error("[not excel dto bean] -> {}" ,targetClassName);
            return null;
        }
        return targetClazz;
    }





}
